package com.by.controller;


import cn.hutool.core.bean.BeanUtil;
import com.by.bean.ProductEnquiry;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.query.ProductEnquiryQuery;
import com.by.query.SupplierProductEnquiryQuery;
import com.by.service.ProductEnquiryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/v1")
@Api(tags = "产品询价")
public class ProductEnquiryController extends BaseController {
    @Autowired
    ProductEnquiryService productEnquiryService;

    @ApiOperation("保存询价")
    @PostMapping("/product/enquiry")
    public ResultBean save(@RequestBody ProductEnquiry enquiry) {
        int rs = productEnquiryService.save(enquiry);
        return saveResult(rs);
    }
    @ApiOperation("查询询价")
    @PostMapping("/product/enquiry/query")
    public ResultBean query(@RequestBody ProductEnquiryQuery query) {
        Map params= BeanUtil.beanToMap(query);
        PageBean bean =productEnquiryService.query(params);
        return success("产品询价列表",bean);
    }

    @ApiOperation("供应商询价")
    @PostMapping("/product/enquiry/supplier")
    public ResultBean querySupplier(@RequestBody SupplierProductEnquiryQuery query) {

        PageBean bean =productEnquiryService.querySupplierProductEnquiry(query);
        return success("供应商询价列表",bean);
    }

}
